package com.itheima.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.order.mapper.OrderMapper;
import com.itheima.order.service.OrderService;
import com.itheima.sh.entity.OrderEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<OrderEntity> findOrderInfoByUserId(Integer userId) {

        QueryWrapper<OrderEntity> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(OrderEntity::getUserId,userId);
        return orderMapper.selectList(wrapper);
    }

    @Override
    @Transactional
    public boolean addOrder(OrderEntity orderEntity) {
        if (orderMapper.insert(orderEntity) > 0){
            return true;
        }
        return false;
    }
}
